home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4585 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.1 KB  |  63 lines

  1. Path: info.spt.net.cn!usenet
  2. From: Xu Yifeng <jafd@public.sta.net.cn>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: ostrstream: Who knows it exectly?
  5. Date: Wed, 31 Jan 1996 06:41:58 -0800
  6. Organization: Shanghai Post & Telecommunication
  7. Message-ID: <310F7FB6.3321@public.sta.net.cn>
  8. References: <4el56r$357@fsuj01.rz.uni-jena.de>
  9. NNTP-Posting-Host: ts1-7.sta.net.cn
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6b (Win16; I)
  14.  
  15. Tilo Koerbs wrote:
  16. > Look at this piece of code:
  17. > ostrstream buf;         // dynamic buffer.
  18. > // Fill buf...
  19. > buf << ends;            // Append NULL-byte.
  20. > char *p = buf.str();    // Freeze buffer.
  21. > And now the problem: The users must delete the buffer
  22. > by there own. But HOW???
  23. > This way:       delete p;
  24. > Or this way:    delete [] p;
  25. > Different books give different answers!
  26. > Is it implementation dependend? (I don't think so!)
  27. > Or can I do both?               (I don't think so too!)
  28.  
  29. Hi,
  30.  
  31. the following is Watcom C++ document:
  32. --------------------------------------------------------
  33.    #include <strstrea.h>
  34.    public:
  35.    char *ostrstream::str();
  36.  
  37. emantics:
  38.    The str public member function creates a pointer to the buffer being
  39.    used by the ostrstream object.  If the ostrstream object was created
  40.    without dynamic allocation (static mode), the pointer is the same as the
  41.    buffer pointer passed in the constructor.
  42.  
  43.    For ostrstream objects using dynamic allocation, the str public member
  44.    function makes an implicit call to the strstreambuf::freeze member
  45.    function.  If nothing has been written to the ostrstream object, the
  46.    returned pointer will be NULL.
  47.  
  48.    Note that the buffer does not necessarily end with a null character.  If
  49.    the pointer returned by the str public member function is to be
  50.    interpreted as a C string, it is the program's responsibility to ensure
  51. ------------------------------------------------------------
  52.  
  53. The document don't say if the dynamic buffer will be automatic freed
  54. or not. but think of its base class, the dynamic buffer should be 
  55. automatic freeed.
  56.  
  57. Regards,
  58. Xu Yifeng
  59.